package com.isunland.managesystem.base;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import java.util.List;

public abstract class BaseListAdapter<T> extends ArrayAdapter<T> {
  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2016-01-20 17:08:33 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  public static class ViewHolder {
    public final LinearLayout mHolderRootView;
    public final LinearLayout mHolderOneVg;
    public final LinearLayout mHolderTwoVg;
    public final LinearLayout mHolderThreeVg;
    public final LinearLayout mHolderFourVg;

    public final TextView mTitleOneTv;
    public final TextView mContentOneTv;
    public final TextView mTitleTwoTv;
    public final TextView mContentTwoTv;
    public final TextView mTitleThreeTv;
    public final TextView mContentThreeTv;
    public final TextView mTitleFourTv;
    public final TextView mContentFourTv;

    public final LinearLayout mHolderFiveVg;
    public final TextView mTitleFiveTv;
    public final TextView mContentFiveTv;
    public final LinearLayout mHolderSixVg;
    public final TextView mTitleSixTv;
    public final TextView mContentSixTv;
    public final LinearLayout mHolderSevenVg;
    public final TextView mTitleSevenTv;
    public final TextView mContentSevenTv;

    public final LinearLayout mHolderEightVg;
    public final TextView mTitleEightTv;
    public final TextView mContentEightTv;

    public final LinearLayout mLlPlanStatus;
    public final TextView mTvPlanStatus;

    private ViewHolder(LinearLayout rootView, LinearLayout holderOneVg, LinearLayout holderTwoVg,
        LinearLayout holderThreeVg, LinearLayout holderFourVg, LinearLayout holderFiveVg,
        LinearLayout holderSixVg, LinearLayout holderSevenVg, LinearLayout holderEightVg,
        LinearLayout llPlanStatus,

        TextView tvTitleOneSimpleList, TextView tvContentOneSimpleList,
        TextView tvTitleTwoSimpleList, TextView tvContentTwoSimpleList,
        TextView tvTitleThreeSimpleList, TextView tvContentThreeSimpleList,
        TextView tvTitleFourSimpleList, TextView tvContentFourSimpleList,

        TextView tvTitleFiveSimpleList, TextView tvContentFiveSimpleList,
        TextView tvTitleSixSimpleList, TextView tvContentSixSimpleList,
        TextView tvTitleSevenSimpleList, TextView tvContentSevenSimpleList,
        TextView tvTitleEightSimpleList, TextView tvContentEightSimpleList, TextView tvPlanStatus) {
      this.mHolderRootView = rootView;
      this.mHolderOneVg = holderOneVg;
      this.mHolderTwoVg = holderTwoVg;
      this.mHolderThreeVg = holderThreeVg;
      this.mHolderFourVg = holderFourVg;
      this.mHolderFiveVg = holderFiveVg;
      this.mHolderSixVg = holderSixVg;
      this.mHolderSevenVg = holderSevenVg;
      this.mHolderEightVg = holderEightVg;
      this.mLlPlanStatus = llPlanStatus;

      this.mTitleOneTv = tvTitleOneSimpleList;
      this.mContentOneTv = tvContentOneSimpleList;
      this.mTitleTwoTv = tvTitleTwoSimpleList;
      this.mContentTwoTv = tvContentTwoSimpleList;
      this.mTitleThreeTv = tvTitleThreeSimpleList;
      this.mContentThreeTv = tvContentThreeSimpleList;
      this.mTitleFourTv = tvTitleFourSimpleList;
      this.mContentFourTv = tvContentFourSimpleList;

      this.mTitleFiveTv = tvTitleFiveSimpleList;
      this.mContentFiveTv = tvContentFiveSimpleList;

      this.mTitleSixTv = tvTitleSixSimpleList;
      this.mContentSixTv = tvContentSixSimpleList;

      this.mTitleSevenTv = tvTitleSevenSimpleList;
      this.mContentSevenTv = tvContentSevenSimpleList;

      this.mTitleEightTv = tvTitleEightSimpleList;
      this.mContentEightTv = tvContentEightSimpleList;

      this.mTvPlanStatus = tvPlanStatus;
    }

    public static ViewHolder create(LinearLayout rootView) {
      LinearLayout holderOneVg = (LinearLayout) rootView.findViewById(R.id.ll_holderOne_simpleList);
      LinearLayout holderTwoVg = (LinearLayout) rootView.findViewById(R.id.ll_holderTwo_simpleList);
      LinearLayout holderThreeVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderThree_simpleList);
      LinearLayout holderFourVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderFour_simpleList);
      TextView tvTitleOneSimpleList = (TextView) rootView.findViewById(R.id.tv_titleOne_simpleList);
      TextView tvContentOneSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentOne_simpleList);
      TextView tvTitleTwoSimpleList = (TextView) rootView.findViewById(R.id.tv_titleTwo_simpleList);
      TextView tvContentTwoSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentTwo_simpleList);
      TextView tvTitleThreeSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleThree_simpleList);
      TextView tvContentThreeSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentThree_simpleList);
      TextView tvTitleFourSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleFour_simpleList);
      TextView tvContentFourSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFour_simpleList);

      LinearLayout holderFiveVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderFive_simpleList);
      TextView tvContentFiveSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFive_simpleList);
      TextView tvTitleFiveSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleFive_simpleList);

      LinearLayout holderSixVg = (LinearLayout) rootView.findViewById(R.id.ll_holderSix_simpleList);
      TextView tvTitleSixSimpleList = (TextView) rootView.findViewById(R.id.tv_titleSix_simpleList);
      TextView tvContentSixSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentSix_simpleList);

      LinearLayout holderSevenVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderSeven_simpleList);
      TextView tvTitleSevenSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleSeven_simpleList);
      TextView tvContentSevenSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentSeven_simpleList);

      LinearLayout holderEightVg =
          (LinearLayout) rootView.findViewById(R.id.ll_holderEight_simpleList);
      TextView tvTitleEightSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleEight_simpleList);
      TextView tvContentEightSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentEight_simpleList);

      LinearLayout llPlanStatus = (LinearLayout) rootView.findViewById(R.id.ll_planStatus);
      TextView tvPlanStatus = (TextView) rootView.findViewById(R.id.tv_planStatus);

      return new ViewHolder(rootView, holderOneVg, holderTwoVg, holderThreeVg, holderFourVg,
          holderFiveVg, holderSixVg, holderSevenVg, holderEightVg, llPlanStatus,

          tvTitleOneSimpleList, tvContentOneSimpleList, tvTitleTwoSimpleList,
          tvContentTwoSimpleList, tvTitleThreeSimpleList, tvContentThreeSimpleList,
          tvTitleFourSimpleList, tvContentFourSimpleList, tvTitleFiveSimpleList,
          tvContentFiveSimpleList, tvTitleSixSimpleList, tvContentSixSimpleList,
          tvTitleSevenSimpleList, tvContentSevenSimpleList, tvTitleEightSimpleList,
          tvContentEightSimpleList, tvPlanStatus);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_recept_detail, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }
    T item = getItem(position);
    bindData(position, vh, item);

    //该通用界面默认有四行,根据行数不同,控制显示和隐藏
    String titleOneStr = vh.mTitleOneTv.getText().toString().trim();
    String titleTwoStr = vh.mTitleTwoTv.getText().toString().trim();
    String titleThreeStr = vh.mTitleThreeTv.getText().toString().trim();
    String titleFourStr = vh.mTitleFourTv.getText().toString().trim();

    String titleFiveStr = vh.mTitleFiveTv.getText().toString().trim();
    String titleSixStr = vh.mTitleSixTv.getText().toString().trim();
    String titleSevenStr = vh.mTitleSevenTv.getText().toString().trim();
    String titleEightStr = vh.mTitleEightTv.getText().toString().trim();
    String planStatus = vh.mTvPlanStatus.getText().toString().trim();

    if (TextUtils.isEmpty(titleOneStr)) {
      vh.mHolderOneVg.setVisibility(View.GONE);
    }
    if (TextUtils.isEmpty(titleTwoStr)) {
      vh.mHolderTwoVg.setVisibility(View.GONE);
    }
    if (TextUtils.isEmpty(titleThreeStr)) {
      vh.mHolderThreeVg.setVisibility(View.GONE);
    }
    if (TextUtils.isEmpty(titleFourStr)) {
      vh.mHolderFourVg.setVisibility(View.GONE);
    }

    if (TextUtils.isEmpty(titleFiveStr)) {
      vh.mHolderFiveVg.setVisibility(View.GONE);
    }
    if (TextUtils.isEmpty(titleSixStr)) {
      vh.mHolderSixVg.setVisibility(View.GONE);
    }
    if (TextUtils.isEmpty(titleSevenStr)) {
      vh.mHolderSevenVg.setVisibility(View.GONE);
    }
    if (TextUtils.isEmpty(titleEightStr)) {
      vh.mHolderEightVg.setVisibility(View.GONE);
    }
    if (TextUtils.isEmpty(planStatus)) {
      vh.mLlPlanStatus.setVisibility(View.GONE);
    }

    return vh.mHolderRootView;
  }

  /**
   * @param position 位置
   * @param vh 界面
   * @param item 数据
   * @return void
   * @Title: bindData
   * @Description: 绑定数据  在绑定数据时必须同时绑定标题和内容.
   */
  public abstract void bindData(int position, final ViewHolder vh, T item);

  private LayoutInflater mInflater;

  // Constructors
  public BaseListAdapter(Context context, List<T> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public BaseListAdapter(Context context, T[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}
